package cn.itsource.system.listener;

import cn.itsource.system.util.PermissionScanUtil;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

/**
 * 自定义类 权限扫描监听器
 */
@WebListener //声明这是一个监听器
public class PermissionScanListener implements ServletContextListener {


    public void contextInitialized(ServletContextEvent sce) {
        //System.out.println("爱上风格打电话给发货");
        //permissionScanUtil.scan();
        //使用WebApplicationContextUtil从ServletContext中获取Spring的ApplicationContext
        ApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(sce.getServletContext());
        //获取Spring管控的对象
        PermissionScanUtil permissionScanUtil = context.getBean("permissionScanUtil", PermissionScanUtil.class);
        new Thread(()->{
            //开始扫描
            permissionScanUtil.scan();
        }).start();
    }
}
